<!-- 福分规则管理 -->
<template>
  <page-header-wrapper>
    <a-card class="table-card">
      <GzSearchForm :searchFunc="searchFunc" :resetFunc="() => { searchData = {} }" searchConditionNum="6">
        <GzTextUp v-model:value="searchData['ifCode']" placeholder="通道编号" />
      </GzSearchForm>

      <!-- 列表渲染 -->
      <GzTable
        ref="infoTableRef"
        :init-data="true"
        :req-table-data-func="reqTableDataFunc"
        :table-columns="tableColumns"
        :search-data="searchData"
      >
        <template #topBtnSlot>
          <a-button v-if="$access('ENT_IFCODE_INFO_ADD')" type="primary" @click="addOrEditFunc(null)">
            <plus-outlined />新建
          </a-button>
        </template>

        <template #bodyCell="{ column, record }">
          <template v-if="column.key === 'isCommSubject'">
            <template v-if="record.isCommSubject === 0">同主体</template>
            <template v-else>异主体</template>
          </template>
          <template v-if="column.key === 'operation'">
            <a-button v-if="$access('ENT_IFCODE_INFO_EDIT')" type="link" @click="addOrEditFunc(record)">修改</a-button>
          </template>
        </template>
      </GzTable>
    </a-card>
    <!-- 新增修改 -->
    <AddOrEdit ref="addOrEditRef" :callbackFunc="searchFunc" />
  </page-header-wrapper>
</template>
<script lang="ts" setup>
import AddOrEdit from './AddOrEdit.vue'
import {$getInvestorList} from '@/api/activityManage/ifCode/index'
import { ref, reactive, getCurrentInstance } from 'vue'

const { $access } = getCurrentInstance()!.appContext.config.globalProperties

const infoTableRef = ref()
const addOrEditRef = ref()

let tableColumns = reactive([
{ key: 'sortNum', title: '排序', dataIndex: 'sortNum', },
  { key: 'ifCode', title: '通道编号', dataIndex: 'ifCode', },
  { key: 'ifName', title: '通道名称', dataIndex: 'ifName', },
  // { key: 'authConfig', title: '通道配置', dataIndex: 'authConfig', width: 140, minWidth: 140, maxWidth: 170 },
  { key: 'isCommSubject', title: '是否为同主体配置', dataIndex: 'isCommSubject', },
  { key: 'operation', title: '操作', dataIndex: 'operation',  align: 'center' }
])

const searchData: any = ref({})

// 请求table接口数据
function reqTableDataFunc(params: any) {
  return $getInvestorList( params)
}

function searchFunc() {
  infoTableRef.value.refTable(true)
}

function addOrEditFunc(record) { // 新建OR修改
  addOrEditRef.value.show(record)
}

</script>